package parser.nodes;

import codegen.ArrayDescr;
import codegen.CodeGen;
import codegen.RecordDescr;
import codegen.VarDescr;
import parser.TokenOr;
import scanner.Token;

// Assignment = ident Selector ':=' Expression
public class AssignmentNode extends DereferenceNode {
    private ExpressionNode expression;

    public AssignmentNode(Token identifier, SelectorNode selector, ExpressionNode expression) {
        super(identifier, selector);
        this.expression = expression;
    }
    
    @Override
    public void print() {
        p("Assignment:");
        indent();
        p(identifier);
        selector.print();
        p(":=");
        expression.print();
        unindent();
    }

    @Override
    public void abstractPrint() {
        p("ASSIGNMENT");
        indent();
        p(identifier);
        selector.abstractPrint();
        expression.abstractPrint();
        unindent();
    }

	@Override
	public void compile(CodeGen c) throws CompileError {
		expression.compile(c); //TODO Expressiontyp für Typprüfung berechnen
		super.compile(c);
		if (lastSize < 0)
			lastSize *= -1;
		c.outstr("ASSIGN, " + lastSize);
	}
}
